package tsif.tcluster.session;

import tsif.tcluster.TClusterContext;

/**
 * 集群连接<br>
 * 连接其他集群环境<br>
 * **/
public abstract class TClusterSession {
	protected TClusterContext context; // 当前依赖Context
	protected int targetContextId;

	public TClusterSession(TClusterContext context, int targetContextId) {
		this.context = context;
		this.targetContextId = targetContextId;
	}

	/** 发送访问(内部调用) **/
	public abstract void send(long sourceServiceId, long targetServiceId, short code, Object data);

	/** 接收消息 **/
	protected void recv(long sourceServiceId, long targetServiceId, short code, Object data) throws Exception {
		context.recv(this, sourceServiceId, targetServiceId, code, data);
	}

	/** 获取连接所依赖的环境(本机的) **/
	public TClusterContext getContext() {
		return context;
	}

	/** 获取连接指向的环境Id(对象) **/
	public int getTargetContextId() {
		return targetContextId;
	}

	/** 关闭连接 **/
	public abstract void close();

	/** 是否有效 **/
	public abstract boolean alive();

}